//
//  MessageVerifyViewController.m
//  DaiShengInvest
//
//  Created by davinci on 17/6/8.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "MessageVerifyViewController.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "BlackNavViewController.h"
#import "HomeViewController.h"
#import "MainTabBarController.h"
#import "RulesViewController.h"

@interface MessageVerifyViewController ()<UIPickerViewDelegate,UIPickerViewDataSource,UITextFieldDelegate>
{
    NSInteger _provinceIndex;   // 省份选择 记录
//    NSInteger _cityIndex;       // 市选择 记录
}

@property (nonatomic, copy)NSString * provinceID;

//@property (nonatomic, copy)NSString * cityID;

@property (nonatomic, strong) UIView *bgview;

@property (nonatomic, weak)UIImageView * backImageView;

@property (nonatomic, weak)UIView * backViewOne;

@property (nonatomic, weak)UILabel * telLabel;

@property (nonatomic, weak)UITextField * telTextField;

@property (nonatomic, weak)UIButton * sentMesButton;

@property (nonatomic, weak)UIView * lineView;

@property (nonatomic, weak)UIView * backViewTwo;

@property (nonatomic, weak)UILabel * verifyLabel;

@property (nonatomic, weak)UITextField * verifyText;

@property (nonatomic, weak)UIView * lineViewTwo;

@property (nonatomic, weak)UIView * backViewThree;

@property (nonatomic, weak)UILabel * passwordLabel;

@property (nonatomic, weak)UITextField * passwordText;

@property (nonatomic, weak)UIView * lineViewThree;

@property (nonatomic, weak)UIView * backViewName;

@property (nonatomic, weak)UILabel * nameLabel;

@property (nonatomic, weak)UITextField * nameText;

@property (nonatomic, weak)UIView * lineViewName;

@property (nonatomic, weak)UIView * backViewFour;

@property (nonatomic, weak)UILabel * emailLabel;

@property (nonatomic, weak)UITextField * emailText;

@property (nonatomic, weak)UIView * cityBackView;

@property (nonatomic, weak)UILabel * cityLabel;

@property (nonatomic, weak)UILabel * sureCityLabel;

@property (nonatomic, weak)UIImageView * rightImageView;

@property (nonatomic, weak)UILabel * recommendLabel;

@property (nonatomic, weak)UIButton * yesButton;

@property (nonatomic, weak)UIButton * noButton;

@property (nonatomic, weak)UIView * recommendWordView;

@property (nonatomic, weak)UILabel * recommendWordLabel;

@property (nonatomic, weak)UITextField * recommendWordText;

@property (nonatomic, weak)UIButton * setupButton;

@property (nonatomic, strong)NSTimer * countDownTimer;

@property (nonatomic, copy)NSString * yesOrNoString;


@property (nonatomic, strong)NSMutableArray * mutableArray;
@property (nonatomic, copy)NSString * isReadString;
@property (nonatomic, weak)UIButton * isReadButton;
@property (nonatomic, weak)UILabel * rulesButton;
@property (nonatomic, weak)UILabel * rulesLastButton;



@end

@implementation MessageVerifyViewController

//倒计时总的秒数
static NSInteger  secondsCountDown = 60;


//显示导航栏
-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = NO;
    
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSString * userID = [userDefaults objectForKey:@"userId"];
    
    NSLog(@"==%@",userID);
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"注册";
    
//    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self setupNavBar];
    [self setupUI];
    [self initData];
    [self resetPickerSelectRow];
    [self setupPivkerView];
    [self addNoticeForKeyboard];
}


- (void)setupNavBar{
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToLogView) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}


- (void)setupUI{
    
    UIImageView * backImage = [[UIImageView alloc] init];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    
    self.backImageView = backImage;
    
    [self.view addSubview:self.backImageView];
    
    
    UIView * backViewOne = [[UIView alloc] init];
    
    backViewOne.backgroundColor = [UIColor whiteColor];
    backViewOne.alpha = 0.1;
    
    self.backViewOne = backViewOne;
    
    [self.view addSubview:self.backViewOne];
    
    UILabel * telLabel = [[UILabel alloc] init];
    
    telLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    telLabel.textColor = [UIColor whiteColor];//ColorWithRGB(0xeeeeee);
    telLabel.text = @"手机号";
    
    self.telLabel = telLabel;
    
    [self.view addSubview:self.telLabel];
    
    UITextField * telText = [[UITextField alloc] init];
    
    telText.borderStyle = UITextBorderStyleNone;
    telText.backgroundColor = [UIColor clearColor];

    //设置光标颜色
    telText.tintColor = ColorWithRGB(0x808486);
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = ColorWithRGB(0x808486);
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    telText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入手机号" attributes:attrs];
    telText.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    telText.textColor = ColorWithRGB(0x808486);
    telText.keyboardType = UIKeyboardTypeNumberPad;
    telText.keyboardAppearance = UIKeyboardAppearanceDark;
    
    self.telTextField = telText;
    
    [self.view addSubview:self.telTextField];
    
    UIButton * sentBtn = [[UIButton alloc] init];
    
    [sentBtn setBackgroundColor:ColorWithRGB(0xa92c44)];
    sentBtn.layer.borderColor = [ColorWithRGB(0xa92c44) CGColor];
    //边框宽度
    sentBtn.layer.borderWidth = 1.0f;
    //处理圆角
    sentBtn.layer.cornerRadius = 3.0f;
    [sentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    sentBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    
    [sentBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [sentBtn addTarget:self action:@selector(didSentMessageButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.sentMesButton = sentBtn;
    
    [self.view addSubview:self.sentMesButton];
    
    UIView * lineView = [[UIView alloc] init];
    
    lineView.backgroundColor = ColorWithRGB(0x526366);
    
    self.lineView = lineView;
    
    [self.view addSubview:self.lineView];
    
    UIView * backViewTwo = [[UIView alloc] init];
    
    backViewTwo.backgroundColor = [UIColor whiteColor];
    backViewTwo.alpha = 0.1;
    
    self.backViewTwo = backViewTwo;
    
    [self.view addSubview:self.backViewTwo];
    
    UILabel * verifty = [[UILabel alloc] init];
    
    verifty.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    verifty.textColor = ColorWithRGB(0xeeeeee);
    verifty.text = @"验证码";
    
    self.verifyLabel = verifty;
    
    [self.view addSubview:self.verifyLabel];
    
    
    UITextField * veriftyText = [[UITextField alloc] init];
    
    veriftyText.borderStyle = UITextBorderStyleNone;
    veriftyText.backgroundColor = [UIColor clearColor];
    
    //设置光标颜色
    veriftyText.tintColor = ColorWithRGB(0x808486);

    veriftyText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes:attrs];
    veriftyText.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    veriftyText.textColor = ColorWithRGB(0x808486);
    veriftyText.keyboardType = UIKeyboardTypeNumberPad;
    veriftyText.keyboardAppearance = UIKeyboardAppearanceDark;
    
    self.verifyText = veriftyText;
    
    [self.view addSubview:self.verifyText];
    
    UIView * lineViewTwo = [[UIView alloc] init];
    
    lineViewTwo.backgroundColor = ColorWithRGB(0x526366);

    self.lineViewTwo = lineViewTwo;
    
    [self.view addSubview:self.lineViewTwo];
    
    
    UIView * backViewThree = [[UIView alloc] init];
    
    backViewThree.backgroundColor = [UIColor whiteColor];
    backViewThree.alpha = 0.1;
    
    self.backViewThree = backViewThree;
    
    [self.view addSubview:self.backViewThree];
    
    UILabel * passwordLabel = [[UILabel alloc] init];
    
    passwordLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    passwordLabel.textColor = ColorWithRGB(0xeeeeee);
    passwordLabel.text = @"密码";
    
    self.passwordLabel = passwordLabel;
    
    [self.view addSubview:self.passwordLabel];
    
    UITextField * passwordText = [[UITextField alloc] init];
    
    passwordText.borderStyle = UITextBorderStyleNone;
    passwordText.backgroundColor = [UIColor clearColor];
    
    //设置光标颜色
    passwordText.tintColor = ColorWithRGB(0x808486);
    
    NSMutableDictionary *attrs2 = [NSMutableDictionary dictionary];
    attrs2[NSForegroundColorAttributeName] = ColorWithRGB(0x808486);
    attrs2[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:8 * SCREENH6];
    
    passwordText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"至少6位，须包含大小写字母及数字" attributes:attrs2];

    passwordText.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    passwordText.textColor = ColorWithRGB(0x808486);
    passwordText.keyboardType = UIKeyboardTypeDefault;
    passwordText.keyboardAppearance = UIKeyboardAppearanceDark;
    passwordText.delegate = self;
    passwordText.secureTextEntry = YES;

    
    self.passwordText = passwordText;
    
    [self.view addSubview:self.passwordText];
    
    UIView * lineViewThree = [[UIView alloc] init];
    
    lineViewThree.backgroundColor = ColorWithRGB(0x526366);
    
    self.lineViewThree = lineViewThree;
    
    [self.view addSubview:self.lineViewThree];
    
    
    UIView * backViewName = [[UIView alloc] init];
    
    backViewName.backgroundColor = [UIColor whiteColor];
    backViewName.alpha = 0.1;
    
    self.backViewName = backViewName;
    
    [self.view addSubview:self.backViewName];
    
    
    UILabel * nameLabel = [[UILabel alloc] init];
    
    nameLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    nameLabel.textColor = ColorWithRGB(0xeeeeee);
    nameLabel.text = @"姓名";
    
    self.nameLabel = nameLabel;
    
    [self.view addSubview:self.nameLabel];
    
    
    UITextField * nameText = [[UITextField alloc] init];
    
    nameText.borderStyle = UITextBorderStyleNone;
    nameText.backgroundColor = [UIColor clearColor];
    
    //设置光标颜色
    nameText.tintColor = ColorWithRGB(0x808486);
    
    nameText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入与身份证一致的姓名" attributes:attrs];
    nameText.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    nameText.textColor = ColorWithRGB(0x808486);
    nameText.keyboardType = UIKeyboardTypeDefault;
    nameText.keyboardAppearance = UIKeyboardAppearanceDark;
    nameText.delegate = self;
    
    self.nameText = nameText;
    
    [self.view addSubview:self.nameText];
    
    
    UIView * lineViewName = [[UIView alloc] init];
    
    lineViewName.backgroundColor = ColorWithRGB(0x526366);
    
    self.lineViewName = lineViewName;
    
    [self.view addSubview:self.lineViewName];
    
    
    
    UIView * backViewFour = [[UIView alloc] init];
    
    backViewFour.backgroundColor = [UIColor whiteColor];
    backViewFour.alpha = 0.1;
    
    self.backViewFour = backViewFour;
    
    [self.view addSubview:self.backViewFour];
    
    UILabel * emailLabel = [[UILabel alloc] init];
    
    emailLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    emailLabel.textColor = ColorWithRGB(0xeeeeee);
    emailLabel.text = @"邮箱";
    
    self.emailLabel = emailLabel;
    
    [self.view addSubview:self.emailLabel];
    
    
    UITextField * emailText = [[UITextField alloc] init];
    
    emailText.borderStyle = UITextBorderStyleNone;
    emailText.backgroundColor = [UIColor clearColor];
    
    //设置光标颜色
    emailText.tintColor = ColorWithRGB(0x808486);
    
    emailText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入常用邮箱" attributes:attrs];
    emailText.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    emailText.textColor = ColorWithRGB(0x808486);
    emailText.keyboardType = UIKeyboardTypeDefault;
    emailText.keyboardAppearance = UIKeyboardAppearanceDark;
    emailText.delegate = self;
    
    self.emailText = emailText;
    
    [self.view addSubview:self.emailText];
    
    
    UIView * cityBack = [[UIView alloc] init];
    
    cityBack.backgroundColor = [UIColor whiteColor];
    cityBack.alpha = 0.1;
    cityBack.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showPickerView)];
    [cityBack addGestureRecognizer:tap];
    
    self.cityBackView = cityBack;
    
    [self.view addSubview:self.cityBackView];
    
    UILabel * cityLabel = [[UILabel alloc] init];
    
    cityLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    cityLabel.textColor = ColorWithRGB(0xeeeeee);
    cityLabel.text = @"省份城市";
    
    self.cityLabel = cityLabel;
    
    [self.view addSubview:self.cityLabel];
    
    
    UILabel * sureCityLabel = [[UILabel alloc] init];
    
    sureCityLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    sureCityLabel.textColor = ColorWithRGB(0xe0e0e0);
    sureCityLabel.textAlignment = NSTextAlignmentRight;
    sureCityLabel.text = @"";
    
    self.sureCityLabel = sureCityLabel;
    
    [self.view addSubview:self.sureCityLabel];
    
    
    UIImageView * rightImageView = [[UIImageView alloc] init];
    
    rightImageView.image = [UIImage imageNamed:@"省份城市"];
    
    self.rightImageView = rightImageView;
    
    [self.view addSubview:self.rightImageView];
    

    UILabel * recommendLabel = [[UILabel alloc] init];
    
    recommendLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    recommendLabel.textColor = ColorWithRGB(0xeeeeee);
    recommendLabel.text = @"是否有推荐人";
    
    self.recommendLabel = recommendLabel;
    
    [self.view addSubview:self.recommendLabel];
    
    
    UIButton * yesButton = [[UIButton alloc] init];
    
    [yesButton setImage:[UIImage imageNamed:@"勾选"] forState:UIControlStateSelected];
    [yesButton setImage:[UIImage imageNamed:@"否"] forState:UIControlStateNormal];
    [yesButton setTitleColor:ColorWithRGB(0xbebebe) forState:UIControlStateNormal];
    [yesButton setTitleColor:ColorWithRGB(0xa92c44) forState:UIControlStateSelected];
    [yesButton setTitle:@"是" forState:UIControlStateNormal];
    [yesButton addTarget:self action:@selector(didYesButton) forControlEvents:UIControlEventTouchUpInside];
    yesButton.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    [yesButton setImageEdgeInsets:UIEdgeInsetsMake(0.0, -5, 0.0, 0.0)];
    [yesButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
//    yesButton.selected = YES;
//    
//    self.yesOrNoString = @"1";
    
    self.yesButton = yesButton;
    
    [self.view addSubview:self.yesButton];
    
    UIButton * noButton = [[UIButton alloc] init];
    
    [noButton setImage:[UIImage imageNamed:@"勾选"] forState:UIControlStateSelected];
    [noButton setImage:[UIImage imageNamed:@"否"] forState:UIControlStateNormal];
    [noButton setTitleColor:ColorWithRGB(0xbebebe) forState:UIControlStateNormal];
    [noButton setTitleColor:ColorWithRGB(0xa92c44) forState:UIControlStateSelected];
    [noButton setTitle:@"否" forState:UIControlStateNormal];
    [noButton addTarget:self action:@selector(didYesButton) forControlEvents:UIControlEventTouchUpInside];
    noButton.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    [noButton setImageEdgeInsets:UIEdgeInsetsMake(0.0, -5, 0.0, 0.0)];
    [noButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
    noButton.selected = YES;
    
    self.yesOrNoString = @"0";
    
    self.noButton = noButton;
    
    [self.view addSubview:self.noButton];
    
    
    
    UIView * recommendWord = [[UIView alloc] init];
    
    recommendWord.backgroundColor = [UIColor whiteColor];
    recommendWord.alpha = 0.1;
    recommendWord.hidden = YES;
    
    self.recommendWordView = recommendWord;
    
    [self.view addSubview:self.recommendWordView];
    
    UILabel * recommendWordLabel = [[UILabel alloc] init];
    
    recommendWordLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    recommendWordLabel.textColor = ColorWithRGB(0xeeeeee);
    recommendWordLabel.text = @"推荐码";
    recommendWordLabel.hidden = YES;
    
    self.recommendWordLabel = recommendWordLabel;
    
    [self.view addSubview:self.recommendWordLabel];
    
    UITextField * recommendWordText = [[UITextField alloc] init];
    
    recommendWordText.borderStyle = UITextBorderStyleNone;
    recommendWordText.backgroundColor = [UIColor clearColor];
    
    //设置光标颜色
    recommendWordText.tintColor = ColorWithRGB(0x808486);
    
    recommendWordText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入推荐码" attributes:attrs];
    recommendWordText.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    recommendWordText.textColor = ColorWithRGB(0x808486);
    recommendWordText.keyboardType = UIKeyboardTypeNumberPad;
    recommendWordText.keyboardAppearance = UIKeyboardAppearanceDark;
    recommendWordText.hidden = YES;
    
    self.recommendWordText = recommendWordText;
    
    [self.view addSubview:self.recommendWordText];
    
    
    UIButton * setupButton = [[UIButton alloc] init];
    
    [setupButton setTitle:@"注册" forState:UIControlStateNormal];
    setupButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];//[UIFont systemFontOfSize:15];
//    [setupButton setBackgroundColor:ColorWithRGB(0xa92c44)];
//    [setupButton setBackgroundImage:[UIImage imageNamed:@"注册"] forState:UIControlStateNormal];
//    setupButton.layer.borderColor = [[UIColor blackColor] CGColor];
    [setupButton setBackgroundColor:[UIColor clearColor]];
    setupButton.layer.borderColor = [[UIColor grayColor] CGColor];
    //        [self.setupButton setImage:[UIImage imageNamed:@"注册"] forState:UIControlStateNormal];
    [setupButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    
    setupButton.userInteractionEnabled = NO;
    //边框宽度
    setupButton.layer.borderWidth =1.0f;
    //处理圆角
    setupButton.layer.cornerRadius =5.0f;
    [setupButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [setupButton addTarget:self action:@selector(didSetupButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.setupButton = setupButton;
    
    [self.view addSubview:self.setupButton];
    
    //    isReadButton
    UIButton * isReadButton = [[UIButton alloc] init];
    
    //    [isReadButton setImage:[UIImage imageNamed:@"勾选"] forState:UIControlStateSelected];
    [isReadButton setImage:[UIImage imageNamed:@"否"] forState:UIControlStateNormal];
    [isReadButton addTarget:self action:@selector(didIsReadButton) forControlEvents:UIControlEventTouchUpInside];
    isReadButton.selected = YES;
    
    self.isReadString = @"0";
    
    self.isReadButton = isReadButton;
    
    [self.view addSubview:self.isReadButton];
    
    
    UILabel * rulesButton = [[UILabel alloc] init];
    
    //    [isReadButton setImage:[UIImage imageNamed:@"勾选"] forState:UIControlStateSelected];
    rulesButton.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    //    rulesButton.text = @"已阅读并同意《风险披露书》";
    rulesButton.textColor = ColorWithRGB(0xeeeeee);
    rulesButton.textAlignment = NSTextAlignmentLeft;
    rulesButton.userInteractionEnabled = YES;
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"已阅读并同意《风险披露书》"];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor redColor]
     
                          range:NSMakeRange(6, 7)];
    
    rulesButton.attributedText = AttributedStr;
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    
    [rulesButton addGestureRecognizer:tapGR];
    
    self.rulesButton = rulesButton;
    
    [self.view addSubview:self.rulesButton];
}


- (void)viewDidLayoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.view);
    }];
    
    [self.backViewOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(345 * SCREENH6);
        make.height.mas_equalTo(54 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(74 * SCREENH6);
    }];
    
    [self.telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backViewOne).offset(9 * SCREENH6);
        make.centerY.mas_equalTo(self.backViewOne);
        make.width.mas_equalTo(45 * SCREENH6);
    }];
    
    [self.telTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backViewOne);
        make.leading.mas_equalTo(self.telLabel.mas_trailing).offset(42 * SCREENH6);
        make.height.mas_equalTo(self.telLabel);
        make.width.mas_equalTo(125 * SCREENH6);
    }];
    
    [self.sentMesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.backViewOne).offset(- 12 * SCREENH6);
        make.width.mas_equalTo(98 * SCREENH6);
        make.height.mas_equalTo(33 * SCREENH6);
        make.centerY.mas_equalTo(self.backViewOne);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
//        make.width.mas_equalTo(323 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.backViewOne);
        make.top.mas_equalTo(self.backViewOne.mas_bottom);
    }];
    
    [self.backViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom);
        make.height.width.leading.trailing.mas_equalTo(self.backViewOne);
    }];
    
    [self.verifyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.telLabel);
        make.centerY.mas_equalTo(self.backViewTwo);
    }];
    
    [self.verifyText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.telTextField);
        make.centerY.mas_equalTo(self.backViewTwo);
    }];
    
    [self.lineViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
        //        make.width.mas_equalTo(323 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.backViewTwo);
        make.top.mas_equalTo(self.backViewTwo.mas_bottom);
    }];
    
    [self.backViewThree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.backViewTwo);
        make.top.mas_equalTo(self.lineViewTwo.mas_bottom);
    }];
    
    [self.passwordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.verifyLabel);
        make.centerY.mas_equalTo(self.backViewThree);
    }];
    
    [self.passwordText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.mas_equalTo(self.verifyText);
        make.centerY.mas_equalTo(self.backViewThree);
        make.trailing.mas_equalTo(self.sentMesButton);
    }];
    
    [self.lineViewThree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
        //        make.width.mas_equalTo(323 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.backViewTwo);
        make.top.mas_equalTo(self.backViewThree.mas_bottom);
    }];
    
    [self.backViewName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.backViewThree);
        make.top.mas_equalTo(self.lineViewThree.mas_bottom);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.passwordLabel);
        make.centerY.mas_equalTo(self.backViewName);
    }];

    [self.nameText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.mas_equalTo(self.passwordText);
        make.width.mas_equalTo(200 * SCREENH6);
        make.centerY.mas_equalTo(self.backViewName);
    }];
    
    [self.lineViewName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
        //        make.width.mas_equalTo(323 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.backViewName);
        make.top.mas_equalTo(self.backViewName.mas_bottom);
    }];
    
    
    [self.backViewFour mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.backViewName);
        make.top.mas_equalTo(self.lineViewName.mas_bottom);
    }];
    
    [self.emailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.passwordLabel);
        make.centerY.mas_equalTo(self.backViewFour);
    }];
    
    [self.emailText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.nameText);
        make.centerY.mas_equalTo(self.backViewFour);
    }];
    
    
    [self.cityBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.backViewFour.mas_bottom).offset(11 * SCREENH6);
        make.leading.trailing.width.height.mas_equalTo(self.backViewFour);
    }];
    
    
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.mas_equalTo(self.emailLabel);
        make.centerY.mas_equalTo(self.cityBackView);
    }];
    
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.cityBackView).offset(-5 * SCREENH6);
        make.centerY.mas_equalTo(self.cityBackView);
        make.width.mas_equalTo(12 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];

    [self.sureCityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.rightImageView.mas_leading).offset(-3 * SCREENH6);
        make.centerY.mas_equalTo(self.cityBackView);
    }];
   
    [self.recommendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.cityBackView.mas_bottom).offset(25 * SCREENH6);
        make.leading.height.mas_equalTo(self.cityLabel);
    }];
    
    
    [self.yesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.recommendLabel);
        make.leading.mas_equalTo(self.recommendLabel.mas_trailing).offset(20 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
        make.width.mas_equalTo(43 * SCREENH6);
    }];
    
    [self.noButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.yesButton);
        make.leading.mas_equalTo(self.yesButton.mas_trailing).offset(22 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
        make.width.mas_equalTo(43 * SCREENH6);
    }];
    
    [self.recommendWordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.height.mas_equalTo(self.cityBackView);
        make.top.mas_equalTo(self.recommendLabel.mas_bottom).offset(25 * SCREENH6);
    }];
    
    [self.recommendWordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.mas_equalTo(self.recommendLabel);
        make.centerY.mas_equalTo(self.recommendWordView);
    }];
    
    [self.recommendWordText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.mas_equalTo(self.emailText);
        make.centerY.mas_equalTo(self.recommendWordView);
    }];
    
    
    [self.setupButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.width.mas_equalTo(self.recommendWordView);
        make.top.mas_equalTo(self.recommendWordView.mas_bottom).offset(43 * SCREENH6);
        make.height.mas_equalTo(48 * SCREENH6);
    }];
    
    [self.rulesButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.setupButton.mas_bottom).offset(5 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
        make.width.mas_equalTo(200 * SCREENH6);
    }];
    
    [self.isReadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.rulesButton.mas_leading).offset(-5 * SCREENH6);
        make.centerY.mas_equalTo(self.rulesButton);
        make.height.mas_equalTo(20 * SCREENH6);
        make.width.mas_equalTo(40 * SCREENH6);
    }];

}


- (void)didIsReadButton{
    
    if ([self.isReadString isEqualToString:@"0"]) {
        
        [self.isReadButton setImage:[UIImage imageNamed:@"勾选"] forState:UIControlStateNormal];
        self.isReadString = @"1";
        
        [self.setupButton setBackgroundColor:[UIColor clearColor]];
        //        [self.setupButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.setupButton.layer.borderColor = [[UIColor clearColor] CGColor];
        [self.setupButton setBackgroundImage:[UIImage imageNamed:@"注册"] forState:UIControlStateNormal];
        
        //边框宽度
        self.setupButton.layer.borderWidth =1.0f;
        //处理圆角
        self.setupButton.layer.cornerRadius =5.0f;
        self.setupButton.userInteractionEnabled = YES;
    }else{
        
        [self.isReadButton setImage:[UIImage imageNamed:@"否"] forState:UIControlStateNormal];
        self.isReadString = @"0";
        
        [self.setupButton setBackgroundColor:[UIColor clearColor]];
        //        [self.setupButton setImage:[UIImage imageNamed:@"注册"] forState:UIControlStateNormal];
        [self.setupButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        
        self.setupButton.layer.borderColor = [[UIColor grayColor] CGColor];
        //边框宽度
        self.setupButton.layer.borderWidth =1.0f;
        //处理圆角
        self.setupButton.layer.cornerRadius =5.0f;
        
        self.setupButton.userInteractionEnabled = NO;
    }
    
}


- (void)tapAction{
    
    RulesViewController * rlesVC = [RulesViewController new];
    
    [self.navigationController pushViewController:rlesVC animated:YES];
}


///键盘显示事件
- (void) keyboardWillShow:(NSNotification *)notification {
    
    if (self.recommendWordText.isFirstResponder) {
        
        //获取键盘高度，在不同设备上，以及中英文下是不同的
        CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
        
        //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
        CGFloat offset = (self.recommendWordText.frame.origin.y + self.recommendWordText.frame.size.height+30 * SCREENH6) - (self.view.frame.size.height - kbHeight);
        
        // 取得键盘的动画时间，这样可以在视图上移的时候更连贯
        double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
        
        //将视图上移计算好的偏移
        
        [UIView animateWithDuration:duration animations:^{
            self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);
        }];
    }
    
    
}

///键盘消失事件
- (void) keyboardWillHide:(NSNotification *)notify {
    
    if (self.recommendWordText.isFirstResponder) {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //视图下沉恢复原状
    [UIView animateWithDuration:duration animations:^{
        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
        
    }
}

#pragma mark - 键盘通知
- (void)addNoticeForKeyboard {
    
    //注册键盘出现的通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification object:nil];
    //注册键盘消失的通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification object:nil];
}


//=============================pickView的创建和点击事件=================

-(void)initData
{
    _provinceIndex = 0;
}

- (void)setupPivkerView{
    
    self.bgview = [[UIView alloc]init];
    self.bgview.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, SCREENH_HEIGHT / 3);
    self.bgview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.bgview];
    
    UIView *btnView = [[UIView alloc]init];
    btnView.frame = CGRectMake(0, 0, self.view.frame.size.width, 40 * SCREENH6);
    btnView.backgroundColor = [UIColor lightGrayColor];
    [self.bgview addSubview:btnView];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(10 * SCREENH6, 5 * SCREENH6, 60 * SCREENH6, 30 * SCREENH6);
    [sureBtn setTitle:@"取消" forState:UIControlStateNormal];
    [sureBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:sureBtn];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(self.view.frame.size.width - 70 * SCREENH6, 5 * SCREENH6, 60 * SCREENH6, 30 * SCREENH6);
    [cancelBtn setTitle:@"确定" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(sureBtn) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:cancelBtn];
    
    float height = SCREENH_HEIGHT / 3 - 40 * SCREENH6;
    self.pickerView = [[UIPickerView alloc]init];
    self.pickerView.frame = CGRectMake(0, 40 * SCREENH6, self.view.frame.size.width, height);
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    [self.bgview addSubview:self.pickerView];
    

}

- (NSMutableArray *)mutableArray{
    
    if (!_mutableArray) {
        
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *path = [bundle pathForResource:@"DCMCity" ofType:@"json"];
        NSData *data = [NSData dataWithContentsOfFile:path];
        NSError *error;
        NSDictionary *provinceLise = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
        //        self.pickerdic = provinceLise;
        NSArray * array = [NSArray array];
        array = provinceLise[@"param"];
        
        NSDictionary * dict1 = array[0];
        NSDictionary * dict2 = array[1];
        NSDictionary * dict3 = array[2];
        NSDictionary * dict4 = array[3];
        NSDictionary * dict5 = array[4];
        
        NSArray * array1 = dict1[@"data"];
        NSArray * array2 = dict2[@"data"];
        NSArray * array3 = dict3[@"data"];
        NSArray * array4 = dict4[@"data"];
        NSArray * array5 = dict5[@"data"];
        
        _mutableArray = [NSMutableArray array];
        
        [_mutableArray addObjectsFromArray:array1];
        [_mutableArray addObjectsFromArray:array2];
        [_mutableArray addObjectsFromArray:array3];
        [_mutableArray addObjectsFromArray:array4];
        [_mutableArray addObjectsFromArray:array5];
    }
    
//    NSLog(@"==%@",_mutableArray);
    
    return _mutableArray;
}


// 读取本地Json加载数据源
//-(NSArray *)arrayDS
//{
//    if(!_arrayDS){
////        NSString * path = [[NSBundle mainBundle] pathForResource:@"Province" ofType:@"plist"];
////        _arrayDS = [[NSArray alloc] initWithContentsOfFile:path];
//        NSBundle *bundle = [NSBundle mainBundle];
//        NSString *path = [bundle pathForResource:@"DCMCity" ofType:@"json"];
//        NSData *data = [NSData dataWithContentsOfFile:path];
//        NSError *error;
//        NSDictionary *provinceLise = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
////        self.pickerdic = provinceLise;
//        _arrayDS = [NSArray array];
//        _arrayDS = provinceLise[@"param"];
//        
//        NSDictionary * dict1 = _arrayDS[0];
//        NSDictionary * dict2 = _arrayDS[1];
//        NSDictionary * dict3 = _arrayDS[2];
//        NSDictionary * dict4 = _arrayDS[3];
//        NSDictionary * dict5 = _arrayDS[4];
//        
//        NSArray * array1 = dict1[@"data"];
//        NSArray * array2 = dict2[@"data"];
//        NSArray * array3 = dict3[@"data"];
//        NSArray * array4 = dict4[@"data"];
//        NSArray * array5 = dict5[@"data"];
//        
//        self.mutableArray = [NSMutableArray array];
//        
//        [self.mutableArray addObjectsFromArray:array1];
//        [self.mutableArray addObjectsFromArray:array2];
//        [self.mutableArray addObjectsFromArray:array3];
//        [self.mutableArray addObjectsFromArray:array4];
//        [self.mutableArray addObjectsFromArray:array5];
//        
//    }
//    return _arrayDS;
//}


-(void)resetPickerSelectRow
{
    [self.pickerView selectRow:_provinceIndex inComponent:0 animated:YES];
//    [self.pickerView selectRow:_cityIndex inComponent:1 animated:YES];
}

#pragma mark - PickerView Delegate

// 列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// 每列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//    if(component == 0){
//        return self.arrayDS.count;
//    }
//    else {
//        return [self.arrayDS[_provinceIndex][@"citys"] count];
//    }
    return self.mutableArray.count;
}

// 返回每一行的内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//    if(component == 0){
//        return self.arrayDS[row][@"value"];
//    }
//    else {
//        
//        return self.arrayDS[_provinceIndex][@"citys"][row][@"value"];
//    }
    
    
    return self.mutableArray[row][@"name"];
}

// 滑动或点击选择，确认pickerView选中结果
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
//    if(component == 0){
        _provinceIndex = row;
//        _cityIndex = 0;
        
//        [self.pickerView reloadComponent:1];
//    }
//    else {
//        _cityIndex = row;
//    }
    
    // 重置当前选中项
    [self resetPickerSelectRow];
}



- (void)sureBtn{
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgview.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, SCREENH_HEIGHT / 3);
    } completion:^(BOOL finished) {
    }];
    
    NSString * address = [NSString stringWithFormat:@"%@", self.mutableArray[_provinceIndex][@"name"]];
    
    self.provinceID = self.mutableArray[_provinceIndex][@"id"];
//    self.cityID = self.arrayDS[_provinceIndex][@"citys"][_cityIndex][@"id"];
    
    self.sureCityLabel.text = address;
}



- (void)cancelBtn{
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgview.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, SCREENH_HEIGHT / 3);
    } completion:^(BOOL finished) {
    }];
   
}



- (void)showPickerView{
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgview.frame = CGRectMake(0, SCREENH_HEIGHT - SCREENH_HEIGHT / 3, SCREEN_WIDTH, SCREENH_HEIGHT / 3);
    }];
    
}



//=============================点击获取验证码，验证手机号。=================

- (void)didSentMessageButton{
    
    BOOL next = [self isMobileNumber:self.telTextField.text];
    
    if (next) {
        
        secondsCountDown = 59;
        
        //设置定时器
        _countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownAction) userInfo:nil repeats:YES];
        
        [self.sentMesButton setTitle:[NSString stringWithFormat:@"%ld秒后重新发送",secondsCountDown] forState:UIControlStateNormal];
        [self.sentMesButton setBackgroundColor:[UIColor clearColor]];
        [self.sentMesButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        
        NSDictionary * parametersDic = @{@"phone":self.telTextField.text,@"cate":@"1"};
        
        [[NetworkTool sharedTools] POST:@"site/sms-very" parameters:parametersDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        }];
        
    }else{
        
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                       message:@"请输入正确的手机号"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }

}


- (BOOL)isMobileNumber:(NSString *)mobileNum {
    
    //    电信号段:133/149/153/180/181/189/173/177
    //    联通号段:130/131/132/155/156/185/186/145/176
    //    移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
    //    虚拟运营商:170/171
    
    NSString *MOBILE = @"^1(3[0-9]|4[579]|5[0-35-9]|8[0-9]|7[0136-8])\\d{8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    
    return [regextestmobile evaluateWithObject:mobileNum];
}


//定时器的方法
- (void)countDownAction{
    
    secondsCountDown --;
    
    [self.sentMesButton setTitle:[NSString stringWithFormat:@"%lds后重新获取",secondsCountDown] forState:UIControlStateNormal];
    [self.sentMesButton setBackgroundColor:[UIColor clearColor]];
    [self.sentMesButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.sentMesButton.enabled = NO;
    //当倒计时到0时做需要的操作，button变成可选状态
    if(secondsCountDown==0){
        
        [_countDownTimer invalidate];
        
        [self.sentMesButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        [self.sentMesButton setBackgroundColor:ColorWithRGB(0xa92c44)];
        [self.sentMesButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        self.sentMesButton.enabled = YES;
    }
}


//点击是否有推荐人，修改button的选中状态
- (void)didYesButton{
    
    if (self.yesButton.selected) {
        
        self.yesButton.selected = NO;
        self.noButton.selected = YES;
        
        self.recommendWordView.hidden = YES;
        self.recommendWordText.hidden = YES;
        self.recommendWordLabel.hidden = YES;
        
        self.yesOrNoString = @"0";
    }else{
        
        self.yesButton.selected = YES;
        self.noButton.selected = NO;
        
        self.recommendWordView.hidden = NO;
        self.recommendWordText.hidden = NO;
        self.recommendWordLabel.hidden = NO;
        
        self.yesOrNoString = @"1";
    }
    
    
}


//点击注侧按钮
- (void)didSetupButton{
    
    if (!self.provinceID || [self.telTextField.text isEqualToString:@""] || [self.verifyText.text isEqualToString:@""] || [self.passwordText.text isEqualToString:@""] || [self.nameText.text isEqualToString:@""] || [self.emailText.text isEqualToString:@""]) {
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                       message:@"请完善注册信息！"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
       
       
    }else{
       [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        
        NSDictionary * parametersDic = @{@"phone":self.telTextField.text,@"password":self.passwordText.text,@"smsVery":self.verifyText.text,@"email":self.emailText.text,@"name":self.nameText.text,@"hasRecommend":self.yesOrNoString,@"recommendCode":self.recommendWordText.text,@"cityId":self.provinceID};
        
        [[NetworkTool sharedTools] POST:@"site/reg" parameters:parametersDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
            NSString * codeString = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            
            if ([codeString isEqualToString:@"0"]) {
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:@"恭喜你注册成功！赶快去登录吧！"
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          //响应事件
                                                                          NSDictionary * paramDict = responseObject[@"param"];
                                                                          
                                                                          NSString * createTimeStr = paramDict[@"createTime"];
                                                                          NSString * lastLoginTimeStr = paramDict[@"lastLoginTime"];
                                                                          NSString * userIdStr = paramDict[@"userId"];
                                                                          
                                                                          NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
                                                                          
                                                                          [userDefaults setObject:createTimeStr forKey:@"createTime"];
                                                                          [userDefaults setObject:lastLoginTimeStr forKey:@"lastLoginTime"];
                                                                          [userDefaults setObject:userIdStr forKey:@"userId"];
                                                                          [userDefaults setObject:self.telTextField.text forKey:@"phone"];
                                                                          [userDefaults setObject:self.passwordText.text forKey:@"password"];
                                                                          
                                                                          [userDefaults synchronize];
                                                                          
                                                                          AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                                                                          
                                                                          MainTabBarController *tabs = [[MainTabBarController alloc] init];
                                                                          
                                                                          appDelegate.window.rootViewController = tabs;
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
                
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseObject[@"msg"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          //响应事件
                                                                          NSLog(@"action = %@", action);
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
                
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
        
    }
    
   
    
    
}


- (void)backToLogView{
    
    if ([self.fromString isEqualToString:@"LoginString"]) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{        
        //切换根视图控制器
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        MainTabBarController *tabs = [[MainTabBarController alloc] init];
        
        appDelegate.window.rootViewController = tabs;
    }
}


- (void)viewDidDisappear:(BOOL)animated{
    
    [_countDownTimer invalidate];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.passwordText resignFirstResponder];
    [self.emailText resignFirstResponder];
    [self.recommendWordText resignFirstResponder];
    
    return YES;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.passwordText resignFirstResponder];
    [self.telTextField resignFirstResponder];
    [self.emailText resignFirstResponder];
    [self.verifyText resignFirstResponder];
    [self.recommendWordText resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
